package com.practice.bootdemo;

import com.practice.bootdemo.common.MyWebSocketClient;
import com.practice.bootdemo.common.SpringBeanUtil2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@MapperScan("com.practice.bootdemo.mapper")
@SpringBootApplication
public class BootdemoApplication  implements CommandLineRunner {

	private static String port;
	@Autowired
	MyWebSocketClient socketClient;

	@Value("${server.port}")
	public void setPort(String port) {
		BootdemoApplication.port = port;
	}

	public static void main(String[] args) {
		ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(BootdemoApplication.class, args);
		SpringBeanUtil2.setApplicationContext(configurableApplicationContext);
		System.out.println("----------系统启动成功-------------");
		System.out.println("doc访问 : http://localhost:"+port+"/doc.html");
	}

	@Override
	public void run(String... args) {
		// 例如，加载一些数据
		System.out.println("执行了应用程序的初始化操作...");
		socketClient.start();
	}
}
